

import java.awt.Graphics2D;
import java.util.Random;

/**
 *
 * @author styfle
 */
public class MovingLine {
    private float speed; //whole line moves at constant speed
    private MovingObject root;

    public MovingLine(int yPos) {
        root = null;
        Random rand = new Random();
        speed = (float)(rand.nextDouble()*(Main.MAX_SPEED-Main.MIN_SPEED) + Main.MIN_SPEED);
        for (int i=0; i<rand.nextInt(Main.MAX_LENGTH-Main.MIN_LENGTH)+Main.MIN_LENGTH; i++) {
            MovingObject o = new MovingObject(-(i*20),yPos,speed,rand.nextInt(255),rand.nextInt(255),rand.nextInt(255));
            add(o);
        }
    }

    public void add(MovingObject n) {
        MovingObject current = root;
        if (current == null) {
            root = n;
            return;
        }
        while (current.next != null) {
            current = current.next;
        }
        current.next = n;

    }

    public void update(Graphics2D g) {
        MovingObject current = root;
        while (current != null) {
            current.draw(g); //updates
            current = current.next;
        }
    }

}
